package com.khong.sale.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.khong.sale.R;
import com.khong.sale.entity.PersonInfo;

public class PersonListAdatpter extends BaseAdapter {
	private Context mContext;
	private List<PersonInfo> data;
	private LayoutInflater mInflater;

	public PersonListAdatpter(Context context, List<PersonInfo> data) {
		this.mContext = context;
		mInflater = LayoutInflater.from(mContext);
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView holder = null;
		PersonInfo dept = data.get(position);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.person_list_item, null);
			holder = new HolderView();
			holder.name = (TextView) convertView.findViewById(R.id.user_name);
			holder.icon = (ImageView) convertView.findViewById(R.id.user_thumb);
		} else {
			holder = (HolderView) convertView.getTag();
		}

		holder.name.setText(dept.getName());
		convertView.setTag(holder);
		return convertView;
	}

	class HolderView {
		ImageView icon;
		TextView name;
	}
}
